package p6_tests;

import static org.junit.Assert.*;
import org.junit.Test;
import animalManagement.*;


public class ExampleTests  {

	private static final Animal CHIPMUNK = Animal.ANIMAL_OBJECTS[0];
	private static final Animal COCKATOO = Animal.ANIMAL_OBJECTS[1];
	private static final Animal FIREFOX = Animal.ANIMAL_OBJECTS[2];
	private static final Animal FLAMINGO = Animal.ANIMAL_OBJECTS[3];
	private static final Animal LION = Animal.ANIMAL_OBJECTS[4];
	private static final Animal ZEBRA = Animal.ANIMAL_OBJECTS[13];
	private static final Animal TIGER = Animal.ANIMAL_OBJECTS[10];
	private static final Animal VULTURE = Animal.ANIMAL_OBJECTS[12];
	private static final Animal LIONESS = Animal.ANIMAL_OBJECTS[5];


	@Test
	public void testDefaultConstructorAndGetSize() {
		SortedListOfImmutables list = new SortedListOfImmutables();
		assertTrue(list.getSize() == 0);
		assertEquals("[  ]", list.toString());
	}

	@Test
	public void testListSimpleAdd() {
		SortedListOfImmutables list = new SortedListOfImmutables();
		for (int i = Animal.ANIMAL_OBJECTS.length - 1; i >= 0; i--) {
			list.add(Animal.ANIMAL_OBJECTS[i]);
		}
		assertEquals(Animal.ANIMAL_OBJECTS.length, list.getSize());
		assertEquals(
				"[ " +
						"Chipmunk, Cockatoo, Firefox, Flamingo, Lion, Lioness, "+
						"Orangutan, Owl, Panda, Tamarin, Tiger, "+
						"Toucan, Vulture, Zebra ]",

						list.toString()
				);

		list.add(CHIPMUNK);
		list.add(COCKATOO);
		list.add(FIREFOX);
		list.add(FLAMINGO);
		list.add(FIREFOX);
		list.add(LION);
		assertEquals(20, list.getSize());
		assertEquals(
				"[ " +
						"Chipmunk, Chipmunk, Cockatoo, Cockatoo, Firefox, Firefox, Firefox, "+
						"Flamingo, Flamingo, Lion, Lion, Lioness, "+
						"Orangutan, Owl, Panda, Tamarin, Tiger, "+
						"Toucan, Vulture, Zebra ]",

						list.toString()
				);
	}	



	@Test
	public void testRemoveExample() {
		SortedListOfImmutables list1 = new SortedListOfImmutables();
		SortedListOfImmutables list2 = new SortedListOfImmutables();

		list1.add(CHIPMUNK);
		list1.add(FIREFOX);
		list1.add(FIREFOX);
		list1.add(LION);
		list1.add(LION);


		list2.add(CHIPMUNK);
		list2.add(CHIPMUNK);
		list2.add(FIREFOX);
		list2.add(LION);
		list2.add(LION);

		list1.remove(list2);

		assertEquals("[ Firefox ]", list1.toString());
	}
	@Test
	public void testRemoveAnotherExample() {
		SortedListOfImmutables list1 = new SortedListOfImmutables();
		SortedListOfImmutables list2 = new SortedListOfImmutables();

		list1.add(CHIPMUNK);
		list1.add(COCKATOO);
		list1.add(FIREFOX);
		list1.add(LION);
		list1.add(LION);
		list1.add(LION);



		list2.add(CHIPMUNK);
		list2.add(CHIPMUNK);
		list2.add(FIREFOX);
		list2.add(LION);
		list2.add(LION);
		list2.add(LION);

		list1.remove(list2);


		assertEquals("[ Cockatoo ]", list1.toString());
	}


	@Test
	public void testAdd(){
		SortedListOfImmutables list1 = new SortedListOfImmutables();
		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list1.add(CHIPMUNK);
		list1.add(LION);
		list1.add(FIREFOX);
		list1.add(CHIPMUNK);
		list1.add(FIREFOX);

		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(FLAMINGO);

		list1.add(list2);
		assertEquals("[ Chipmunk, Chipmunk, Chipmunk, Firefox, Firefox, Flamingo, Lion, Lion" + " ]",list1.toString());

	}

	@Test
	public void testAvailability(){
		SortedListOfImmutables list = new SortedListOfImmutables();
		list.add(CHIPMUNK);
		list.add(FIREFOX);
		list.add(LION);

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);

		assertTrue(list.checkAvailability(list2));
	}

	@Test
	public void testAnotherAvailable(){
		SortedListOfImmutables list = new SortedListOfImmutables();
		list.add(CHIPMUNK);
		list.add(FIREFOX);
		list.add(LION);

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(COCKATOO);
		list2.add(FLAMINGO);
		list2.add(COCKATOO);

		assertFalse(list.checkAvailability(list2));

	}

	public void testAgainAvailability(){
		SortedListOfImmutables list = new SortedListOfImmutables();
		list.add(CHIPMUNK);
		list.add(FIREFOX);
		list.add(LION);
		list.add(LION);
		list.add(LION);
		list.add(LION);

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);

		assertTrue(list.checkAvailability(list2));
	}

	@Test
	public void testGet(){

		SortedListOfImmutables list = new SortedListOfImmutables();

		list.add(CHIPMUNK);
		list.add(LION);
		list.add(FLAMINGO);
		list.add(FIREFOX);

		assertEquals("Chipmunk", list.get(0).getName());
		assertEquals("Lion", list.get(3).getName());

		list.remove(FIREFOX);
		assertEquals("Flamingo", list.get(1).getName());

		list.add(ZEBRA);
		assertEquals("Zebra", list.get(3).getName());

		list.remove(CHIPMUNK);
		list.add(COCKATOO);
		list.add(TIGER);
		assertEquals("Cockatoo", list.get(0).getName());
		assertEquals("Tiger", list.get(3).getName());
		assertEquals(5, list.getSize());

		list.remove(ZEBRA);
		list.add(CHIPMUNK);
		list.add(FIREFOX);
		list.add(LION);
		list.add(VULTURE);
		list.add(LIONESS);
		list.add(ZEBRA);
		assertEquals(10, list.getSize());
		assertEquals("Chipmunk", list.get(0).getName());
		String expected = "[ Chipmunk, Cockatoo, Firefox, Flamingo, Lion, " +
				"Lion, Lioness, Tiger, Vulture, Zebra ]";
		assertEquals(expected, list.toString());

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(FLAMINGO);
		list2.add(ZEBRA);

		list.remove(list2);
		assertEquals("Cockatoo", list.get(0).getName());
		assertEquals("Vulture", list.get(list.getSize()-1).getName());
		expected = "[ Cockatoo, Firefox, Lion, " +
				"Lioness, Tiger, Vulture ]";
		assertEquals(expected, list.toString());

	}

	@Test
	public void testGetWholeSaleCost(){
		//		"Chipmunk", 8900,  
		//		"Cockatoo", 17800,
		//		"Firefox", 4700, 
		//		"Flamingo", 7700, 
		//		"Lion", 5200, 
		//		"Lioness", 6600, 
		//		"Orangutan", 12700, 
		//		"Owl", 17900, 
		//		"Panda", 6700, 
		//		"Tamarin", 12900, 
		//		"Tiger", 8900, 
		//		Toucan", 9800, 
		//		"Vulture", 19500, 
		//		"Zebra", 10600, 

		SortedListOfImmutables list = new SortedListOfImmutables();

		list.add(CHIPMUNK); //8900
		list.add(LION); //5200
		list.add(FLAMINGO); //7700
		list.add(FIREFOX); //4700
		assertEquals(26500, list.getWholesaleCost());

		list.remove(FIREFOX);//4700
		assertEquals(21800, list.getWholesaleCost());

		list.add(ZEBRA);//10600
		assertEquals(32400, list.getWholesaleCost());

		list.remove(CHIPMUNK);//8900
		list.add(COCKATOO);//17800
		list.add(TIGER);//8900
		assertEquals(50200, list.getWholesaleCost());


		list.remove(ZEBRA);//10600
		list.add(CHIPMUNK);//8900
		list.add(FIREFOX);//4700
		list.add(LION);//5200
		list.add(VULTURE);//19500
		list.add(LIONESS);//6600
		list.add(ZEBRA);//10600
		assertEquals(95100, list.getWholesaleCost());

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK); //8900
		list2.add(LION);//5200
		list2.add(FLAMINGO);//7700
		list2.add(ZEBRA);//10600

		list.remove(list2);
		assertEquals(62700, list.getWholesaleCost());
	}

	@Test
	public void testGetRetail(){

		//		"Chipmunk" 18500, 
		//		"Cockatoo",35000, 
		//		"Firefox", 8900, 
		//		"Flamingo",19900, 
		//		"Lion", 17900, 
		//		"Lioness", 12500, 
		//		"Orangutan", 19500,
		//		"Owl", 35000, 
		//		"Panda", 12500, 
		//		"Tamarin", 27500, 
		//		"Tiger", 12900, 
		//		"Toucan", 15900, 
		//		"Vulture", 27500, 
		//		"Zebra", 12500, 

		SortedListOfImmutables list = new SortedListOfImmutables();

		list.add(CHIPMUNK); //18500
		list.add(LION); //17900
		list.add(FLAMINGO); //19900
		list.add(FIREFOX); //8900
		assertEquals(65200, list.getRetailValue());

		list.remove(FIREFOX);//8900
		assertEquals(56300, list.getRetailValue());

		list.add(ZEBRA);//12500
		assertEquals(68800, list.getRetailValue());

		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK); //18500
		list2.add(LION);//17900
		list2.add(FLAMINGO);//19900
		list2.add(ZEBRA);//12500

		list.remove(list2);
		assertEquals(0, list.getRetailValue());
		list.add(list2);
		assertEquals(68800, list.getRetailValue());
	}

	@Test
	public void testCheckAvailability(){

		SortedListOfImmutables list = new SortedListOfImmutables();

		list.add(CHIPMUNK);
		list.add(LION);
		list.add(FLAMINGO);
		list.add(FIREFOX);

		assertTrue(list.checkAvailability(FLAMINGO));
		assertTrue(list.checkAvailability(CHIPMUNK));

		list.remove(FIREFOX);
		// chipmunk, flamingo, lion
		assertFalse(list.checkAvailability(FIREFOX));

		list.add(ZEBRA);
		// chipmunk, flamingo,lion,  zebra
		assertTrue(list.checkAvailability(ZEBRA));


		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(FLAMINGO);

		// list = chipmunk, flamingo, lion,  zebra
		// iist2 = chipmunk, flamingo, lion
		assertTrue(list.checkAvailability(list2));
		list.remove(list2);
		// list = zebra
		assertFalse(list.checkAvailability(list2));

		list.add(list2); 
		list.add(COCKATOO);
		list.add(COCKATOO);
		list2.add(COCKATOO);
		list2.add(COCKATOO);

		// list = chipmunk, cockatoo, cockatoo, flamingo, lion, zebra
		// list2 = chipmunk, cockatoo, cockatoo, flamingo, lion
		assertTrue(list.checkAvailability(list2));

		list.remove(COCKATOO);
		// list = chipmunk, cockatoo, flamingo, lion, zebra
		// list2 = chipmunk, cockatoo, cockatoo, flamingo, lion
		assertFalse(list.checkAvailability(list2));


	}

	@Test
	public void testMenagerie(){
		SortedListOfImmutables list1 = new SortedListOfImmutables();
		for (int i = Animal.ANIMAL_OBJECTS.length - 1; i >= 0; i--) {
			list1.add(Animal.ANIMAL_OBJECTS[i]);
		}

		SortedListOfImmutables list2 = new SortedListOfImmutables();

		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(FLAMINGO);
		list2.add(FIREFOX);

		Menagerie set1 = new Menagerie("Long List", list1);
		Menagerie set2 = new Menagerie("Short List", list2);

		// test getName()
		assertEquals("Long List", set1.getName());
		assertEquals("Short List", set2.getName());

		// test getAnimalList()
		assertTrue(set1.getAnimalList().toString().equals(list1.toString()));
		assertTrue(set2.getAnimalList().toString().equals(list2.toString()));
		assertFalse(set1.getAnimalList().toString().equals(list2.toString()));

		// test getWholeSaleCost()
		assertEquals(149900, set1.getWholesaleCost());
		assertEquals(26500, set2.getWholesaleCost());

		//test getRetailValue()
		assertEquals(276000, set1.getRetailValue());
		assertEquals(65,200, set2.getRetailValue());

		//test equals(Object other)
		//		Menagerie set3 = new Menagerie("Short List", null);
		//		assertTrue(set2.equals(set3));
		Menagerie	  set3 = new Menagerie("Short List", list2);
		assertTrue(set2.equals(set3));
		set3 = new Menagerie("Short List", list1);
		assertTrue(set2.equals(set3));


		// test toString()
		String expectedStr = "< Chipmunk, Cockatoo, Firefox, Flamingo, Lion, "+
				"Lioness, Orangutan, Owl, Panda, Tamarin, Tiger, Toucan, " +
				"Vulture, Zebra >";
		assertEquals(expectedStr, set1.toString());
		expectedStr = "< Chipmunk, Firefox, Flamingo, Lion >";
		assertEquals(expectedStr, set2.toString());

	}

	@Test
	public void testPetStore(){

		// test constructor
		PetStore store1 = new PetStore("Mimi", 300000);
		assertEquals("Mimi", store1.getName());
		assertEquals(300000, store1.getCash());


		// test addMenagerie and getMenu
		SortedListOfImmutables list1 = new SortedListOfImmutables();
		for (int i = Animal.ANIMAL_OBJECTS.length - 1; i >= 0; i--) {
			list1.add(Animal.ANIMAL_OBJECTS[i]);
		}
		SortedListOfImmutables list2 = new SortedListOfImmutables();
		list2.add(CHIPMUNK);
		list2.add(LION);
		list2.add(FLAMINGO);
		list2.add(FIREFOX);

		Menagerie set1 = new Menagerie("Long List", list1);
		Menagerie set2 = new Menagerie("Short List", list2);

		store1.addMenagerie(set1);
		String expectedStr = "[ < Chipmunk, Cockatoo, Firefox, Flamingo, Lion, "+
				"Lioness, Orangutan, Owl, Panda, Tamarin, Tiger, Toucan, " +
				"Vulture, Zebra > ]";
		assertEquals(expectedStr, store1.getMenu().toString());
		store1.addMenagerie(set2);	
		expectedStr = "[ < Chipmunk, Cockatoo, Firefox, Flamingo, " +
				"Lion, Lioness, Orangutan, Owl, Panda, Tamarin, " +
				"Tiger, Toucan, Vulture, Zebra >, < Chipmunk, " +
				"Firefox, Flamingo, Lion > ]";
		assertEquals(expectedStr, store1.getMenu().toString());

		//test addShipmentToInventory
		assertTrue(store1.addShipmentToInventory(list2));
		assertTrue(store1.checkIfInInventory(set2));
		expectedStr = "[ Chipmunk, Firefox, Flamingo, Lion ]";
		assertEquals(expectedStr, store1.getInventory().toString());

	
	}


}
